package com.zues.thread.lock.reent;

import com.zues.thread.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * ReentrantLock可打断测试
 * @author zues
 * @date 2/24/2025 10:26 下午
 */
@Slf4j(topic = "c.Demo2")
public class Demo2 {




    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        Thread t1 = new Thread(() -> {
            try {
                log.debug("进入t1线程...");
                lock.lockInterruptibly();
            } catch (InterruptedException e) {
                log.debug("被打断，没有获得锁...");
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }, "t1");
        lock.lock();
        t1.start();
        ThreadUtil.sleep(1);
        t1.interrupt();

    }

}
